package com.ty.controller;

import com.alibaba.druid.sql.visitor.functions.If;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Collection;

@Component

public class CustomPermissionEvaluator implements PermissionEvaluator {
    @Override
    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
        if(permission.equals("PO_INTERRUPT")){
            Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
            boolean b =  authorities.stream().anyMatch(authorty ->{
                return authorty.getAuthority().equals("permission");
            });
            return b;
        }
        return false;
        }

    @Override
    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
        return false;
    }
}
